package tutorial.main.control;

import tutorial.entidades.Evento;
import tutorial.main.R;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

public class NotificationServer {

	static NotificationManager myNotificationManager;
	private static final int NOTIFICATION_ID = 1;
	

	 public void GenerarNotification(Context cont, String mensaje, String title,String contenido, boolean vibrar, boolean sonar, boolean light, int icon)
	 {
		  String ns = Context.NOTIFICATION_SERVICE;
	  	  myNotificationManager =  (NotificationManager)cont.getSystemService(ns);
	  	  
	  	  CharSequence NotificationTicket = mensaje;
	  	  CharSequence NotificationTitle = title;
	  	  CharSequence NotificationContent = contenido;
	  	  long when = System.currentTimeMillis();
	  	  
	  	  Notification notification = new Notification(icon,
	  	     NotificationTicket, when);
	  	    
	  	  if (sonar == true){
	  		notification.defaults |= Notification.DEFAULT_SOUND;

	  	  }
	  	  if (vibrar == true){
	  		notification.defaults |= Notification.DEFAULT_VIBRATE;
	  		  //notification.vibrate = new long[]{100, 250, 100, 500};
	  	  }
	  	  if (light == true){
	  		notification.defaults |= Notification.DEFAULT_LIGHTS;

	  	  }
	  	  notification.defaults |= Notification.DEFAULT_LIGHTS;

	  	  Context context = cont;

	  	  Intent notificationIntent = new Intent (cont, Class.class);
	  	  PendingIntent contentIntent = PendingIntent.getActivity(cont, 0, notificationIntent, 0);

	  	  notification.setLatestEventInfo(context, NotificationTitle,
	  	    NotificationContent, contentIntent);
	  	  
	  	  myNotificationManager.notify(NOTIFICATION_ID, notification);

	  	}

	 	public void NotificarConexion(Context cont, Evento e)
	 	{
	 		String mensaje = "";
	 		String title   = "";
	 		String contenido = "";
	 		int icon = 0;
	 		
	 		if(e.getEstadoConetado()==true)
	 		{
	 			// Esta conectado
	 			title = cont.getString(R.string.ns_titulo_conn);
	 			mensaje = cont.getString(R.string.ns_mensaje_conn);
	 			contenido = cont.getString(R.string.ns_contenido_conn)+" "+e.getTipoConexion();
	 			icon = R.drawable.ns_on;
	 		}
	 		else
	 		{
	 			// No lo esta
	 			title = cont.getString(R.string.ns_titulo_noconn);
	 			mensaje = cont.getString(R.string.ns_mensaje_noconn);
	 			contenido = cont.getString(R.string.ns_contenido_noconn);	 
	 			icon = R.drawable.ns_off;
	 		}
	 		this.GenerarNotification(cont, mensaje, title, contenido, true, true, false, icon);
	 	}
	 
}
